<!DOCTYPE html>
<html xmlns=http://www.w3.org/1999/xhtml xmlns:bd=http://www.baidu.com/2010/xbdml>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link Rel="SHORTCUT ICON" href="/pc/login/img/logo1.png">
 <link rel="stylesheet" href="/pc/layui/css/layui.css" media="all" />
 <link rel="stylesheet" href="/pc/layout/css/font_eolqem241z66flxr.css" media="all" />
<script type="text/javascript" src="/pc/layout/js/jquery.min.js"></script>
<script type="text/javascript" src="/pc/layui/layui.js"></script>
 <script type="text/javascript" src="/pc/role/js/urp.js"></script>
<title>权限列表</title>
<style type="text/css">
  input,button,select,textarea{  
     outline:none;
} 
    ul,li{
    list-style: none;
       
    }
    .hide{
      display: none;
     } 
     span{
      cursor:pointer;
     }

</style>
</head>
<body>
 
<div class="main-page">
    {{ csrf_field() }}
    <input type="hidden" name="roleId" value="{{$get['roleId']}}">
        <ul style="margin-left: 7em;margin-top: 1em;">
            @if($authInfo)
                @foreach($authInfo as $val)
                    <li><input type="checkbox" name="auth" value="{{$val['id']}}" parent="{{$val['module']}}" @if(in_array($val['id'],$urp)) checked @endif><span parent="{{$val['module']}}">{{$val['title']}}</span></li>
                    <ul children="{{$val['module']}}">
                      @foreach($val['children'] as $v)
                         <li style="margin-top: .2em;margin-left: 13px" ><input type="checkbox" name="auth" value="{{$v['id']}}" children="{{$val['module']}}" @if(in_array($v['id'],$urp)) checked @endif>{{$v['title']}}</li>
                      @endforeach
                    </ul>
                @endforeach
            @endif
        </ul>
        
</div>

<input type="submit" id="sub" lay-submit="" class="gray" style="width: 5em;height: 2.2em;background-color: #1AA094;   margin-left: 7em;margin-top: 1em;" name="Submit" lay-filter="urpRole" value="提交"> 
</body>
<script>
    $('span').click(function () {
        var p = $(this).attr('parent')
        $('ul[children='+p+']').toggleClass('hide')
    })
    $('input[name=auth]').click(function () {
        var bool = $(this).is(':checked')
        var p = $(this).attr('parent')
        if(bool){
            $('input[children='+p+']').prop('checked',true)
        }else{
            $('input[children='+p+']').prop('checked',false)
        }
    })
    $('input[name=auth]').click(function () {
        var temp = false;
        var bool = $(this).is(':checked')
        var c = $(this).attr('children')
        $('input[children='+c+']').each(function () {
            if($(this).is(':checked')){
                temp = true;
            }
        })
        if(temp){
            $('input[parent='+c+']').prop('checked',true)
        }else{
            $('input[parent='+c+']').prop('checked',false)
        }
    })

    //  $('#sub').click(function () {
    //     var authArr = new Array();
    //     $('input[name=auth]:checked').each(function () {
    //         authArr.push($(this).val());
    //     })
    //     $.ajax({
    //         type:'post',
    //         url:'/admin/role/urp',
    //         async:false,
    //         data:{
    //             '_token':$('input[name=_token]').val(),
    //             'roleId':$('input[name=authId]').val(),
    //             "authArr":authArr
    //         },
    //         dataType:'json',
    //         success:function (data) {
    //             if(data.status == 1){
    //             }
    //         }
    //     })
    // })
</script>
</html>